package com.java.basis.thread.n3;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * park 与 unpark，暂停与恢复
 * unpark可以在park之前调用，也可以在park之后调用
 *
 * @author wangning
 * @create 2022-01-21 16:02
 */
@Slf4j(topic = "c.TestParkUnpark")
public class TestParkUnpark {
	public static void main(String[] args) throws InterruptedException {
		Thread t1 = new Thread(() -> {
			try {
				log.debug("start...");
				Thread.sleep(1000);
				log.debug("park...");
				LockSupport.park();
				log.debug("resume...");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		}, "t1");
		t1.start();
		Thread.sleep(2000);
		log.debug("unpark...");
		LockSupport.unpark(t1);
	}
}
